package klochkov.snake.model;

import klochkov.snake.common.GameState;

/**
 * Represent abstract entity
 * @author Dmitry_Klochkov
 *
 */
public abstract class Entity implements Runnable {
	private final Game game;
	
	public Entity(Game game){
		this.game = game;
	}
	
	/**
	 * This method should be implemented in child classes, is used for 
	 * moving specific game entity on the game field
	 */
	public abstract void move();
	
	public void run(){
		while(true){
			if(game.getState()==GameState.STARTED){
				move();
				//notify observers
			}else if(game.getState()==GameState.PAUSED){
				try {
					wait();
				} catch (InterruptedException e) {}
			}
			if(game.getState() == GameState.GAME_OVER){
				return;
			}
		}
		
	}
}
